package packageCommand;

import java.util.HashMap;
import java.util.Map;

import packagecmdimp.ExitCommand;
import packagecmdimp.HelpCommand;
import packagecmdimp.ListUserCommand;
import packagecmdimp.MerchantLoginCommand;
import packagecmdimp.MerchantSignupCommand;
import packagecmdimp.ListMerchantCommand;
import packagecmdimp.UserLoginCommand;
import packagecmdimp.UserSignupCommand;

public class SystemCommandFactory extends CommandFactory {
    
    private static Map<CommandCode, Class<? extends Command>> commandMap = new HashMap<>();

    static {
        commandMap.put(CommandCode.EXIT, ExitCommand.class);
        commandMap.put(CommandCode.HELP, HelpCommand.class);
        commandMap.put(CommandCode.USERLOGIN, UserLoginCommand.class);
        commandMap.put(CommandCode.USERSIGNUP, UserSignupCommand.class);
        commandMap.put(CommandCode.MERCHANTLOGIN, MerchantLoginCommand.class);
        commandMap.put(CommandCode.MERCHANTSIGNUP, MerchantSignupCommand.class);
        commandMap.put(CommandCode.LISTMERCHANT, ListMerchantCommand.class);
        commandMap.put(CommandCode.LISTUSER, ListMerchantCommand.class);
        //commandMap.put(CommandCode.LISTUSER, ListUserCommand.class);
    }

    public Command buildCommand(CommandCode cmdCode) {
        
        Class<? extends Command> cmdClass = commandMap.get(cmdCode);
        
        if (cmdClass != null) {
            try {
                return cmdClass.newInstance();
            } catch (InstantiationException | IllegalAccessException e) {
                e.printStackTrace();
            }
        }

        return null;
    }
}
